package 队列;
public class test2 {
    public static void main(String[] args) throws Exception {
        System.out.println("假设n=9，k=1，m=5" );
        josph(9,1,5);
        System.out.println();
        System.out.println("假设n=9，k=5，m=2 ");
        josph(9,5,2);
    }
//n 人的个数 ,k开始报数的人，数到m出局 ---
    public static void josph(int n,int k,int m) throws Exception {
        CirQueue c = new CirQueue(n+2);
        //先存N个人
        for (int i = 0; i <n; i++) {
            c.append(i+1);
        }
        System.out.println("出局顺序为：");
        //
        int num=2;
        while(!c.isEmpty()){
            num++;
            c.append(c.delete());
            if(num==k+m){
                System.out.print(c.delete()+" ");
                break;
            }
        }
        int count=1;
        while (!c.isEmpty()){
            c.append(c.delete());
            count++;
            if(count==m){
                System.out.print(c.delete());
                count=1;
            }
        }
    }
}
